package com.web.dao;

import com.web.controller.web.WebWithdrawController;
import com.web.entity.WithdrawApply;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @author FDjavaone
 */
public class WithdrawApplySqlProvider {


    public String insertSelective(WithdrawApply record) {
        BEGIN();
        INSERT_INTO("t_withdraw_apply");

        if (record.getmId() != null) {
            VALUES("m_id", "#{mId,jdbcType=BIGINT}");
        }

        if (record.getName() != null) {
            VALUES("name", "#{name,jdbcType=VARCHAR}");
        }

        if (record.getPhone() != null) {
            VALUES("phone", "#{phone,jdbcType=VARCHAR}");
        }

        if (record.getReason() != null) {
            VALUES("reason", "#{reason,jdbcType=VARCHAR}");
        }

        if (record.getAccount() != null) {
            VALUES("account", "#{account,jdbcType=VARCHAR}");
        }

        if (record.getAmt() != null) {
            VALUES("amt", "#{amt,jdbcType=DECIMAL}");
        }

        if (record.getType() != null) {
            VALUES("type", "#{type,jdbcType=INTEGER}");
        }

        if (record.getBankName() != null) {
            VALUES("bank_name", "#{bankName,jdbcType=VARCHAR}");
        }

        if (record.getCardNo() != null) {
            VALUES("card_no", "#{cardNo,jdbcType=VARCHAR}");
        }

        if (record.getPoundageRate() != null) {
            VALUES("poundage_rate", "#{poundageRate,jdbcType=DECIMAL}");
        }

        if (record.getPoundage() != null) {
            VALUES("poundage", "#{poundage,jdbcType=DECIMAL}");
        }

        if (record.getStatus() != null) {
            VALUES("status", "#{status,jdbcType=INTEGER}");
        }

        if (record.getRecordId() != null) {
            VALUES("record_id", "#{recordId,jdbcType=BIGINT}");
        }

        if (record.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            VALUES("modify_time", "#{modifyTime,jdbcType=TIMESTAMP}");
        }

        return SQL();
    }


    public String updateByPrimaryKeySelective(WithdrawApply record) {
        BEGIN();
        UPDATE("t_withdraw_apply");

        if (record.getmId() != null) {
            SET("m_id = #{mId,jdbcType=BIGINT}");
        }

        if (record.getName() != null) {
            SET("name = #{name,jdbcType=VARCHAR}");
        }

        if (record.getPhone() != null) {
            SET("phone = #{phone,jdbcType=VARCHAR}");
        }

        if (record.getReason() != null) {
            SET("reason = #{reason,jdbcType=VARCHAR}");
        }

        if (record.getAccount() != null) {
            SET("account = #{account,jdbcType=VARCHAR}");
        }

        if (record.getAmt() != null) {
            SET("amt = #{amt,jdbcType=DECIMAL}");
        }

        if (record.getType() != null) {
            SET("type = #{type,jdbcType=INTEGER}");
        }

        if (record.getBankName() != null) {
            SET("bank_name = #{bankName,jdbcType=VARCHAR}");
        }

        if (record.getCardNo() != null) {
            SET("card_no = #{cardNo,jdbcType=VARCHAR}");
        }

        if (record.getPoundageRate() != null) {
            SET("poundage_rate = #{poundageRate,jdbcType=DECIMAL}");
        }

        if (record.getPoundage() != null) {
            SET("poundage = #{poundage,jdbcType=DECIMAL}");
        }

        if (record.getStatus() != null) {
            SET("status = #{status,jdbcType=INTEGER}");
        }

        if (record.getRecordId() != null) {
            SET("record_id = #{recordId,jdbcType=BIGINT}");
        }

        if (record.getCreateTime() != null) {
            SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            SET("modify_time = #{modifyTime,jdbcType=TIMESTAMP}");
        }

        WHERE("id = #{id,jdbcType=BIGINT}");

        return SQL();
    }


    public String selectAllwithdraws(WebWithdrawController.WithdrawColumns record) {
        BEGIN();
        SELECT("id");
        SELECT("m_id");
        SELECT("name");
        SELECT("phone");
        SELECT("reason");
        SELECT("account");
        SELECT("amt");
        SELECT("type");
        SELECT("bank_name");
        SELECT("card_no");
        SELECT("poundage_rate");
        SELECT("poundage");
        SELECT("status");
        SELECT("record_id");
        SELECT("create_time");
        SELECT("modify_time");
        FROM("t_withdraw_apply");

        if (record.getName() != null && !"".equals(record.getName())) {
            WHERE("name like #{name,jdbcType=VARCHAR}");
        }
        if (record.getPhone() != null && !"".equals(record.getPhone())) {
            WHERE("phone like #{phone,jdbcType=VARCHAR}");
        }
        if (record.getType() != null && !"".equals(record.getType())) {
            WHERE("type = #{type,jdbcType=INTEGER}");
        }

        if (record.getStatus() != null && !"".equals(record.getStatus())) {
            WHERE("status = #{status,jdbcType=INTEGER}");
        }

        if(record.getBegin_createTime()!=null){
            WHERE("create_time >= #{begin_createTime,jdbcType=TIMESTAMP}");
        }
        if(record.getEnd_createTime()!=null){
            WHERE("create_time <= #{end_createTime,jdbcType=TIMESTAMP}");
        }

        ORDER_BY("create_time desc");

        return SQL();
    }


}